Cottus   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 13
dl 0
loc 24
c 0
b 0
f 0
rs 10

4 Functions

Rating   Name   Duplication   Size   Complexity  
A constructor 0 4 1
A addRules 0 5 3
A addRule 0 3 1
A compile 0 7 1
1
import { toArray } from 'myrmidon';
2
import Validator from './Validator';
3
4
export default class Cottus {
5
    constructor(conf = {}) {
6
        this.rules = {};
7
        this.addRules(conf.rules || []);
8
    }
9
10
    compile(schema, parentContext) {
11
        const validator = new Validator(this, schema, parentContext);
12
13
        validator.parse();
14
15
        return validator;
16
    }
17
18
    addRules(rules) {
19
        rules.forEach(rule => {
20
            toArray(rule.schema).forEach(schemaKey => this.rules[schemaKey] = rule);
21
        });
22
    }
23
24
    addRule(rule) {
25
        this.addRules([ rule ]);
26
    }
27
}
28